// pages/guide/guide.js
const app = getApp();
var utils = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    search: {
      img: '/images/position/search.png'
    },
    num: 1,
    type: '业态',
    address: '区域',
    more: '高级',
    prolist: [],
    select: [
      '所有', '潮流服饰', '珠宝饰品', '数码电子'
    ],
    showSelect:false,
    warpHeight:0,//蒙层高度
    pageHeight:'',//页面高度
    changePageHeight:0
  },
  //点击tab
  tabClick(e) {
    var that = this;
    this.setData({
      num: e.target.dataset.num,
      showSelect: !this.data.showSelect
    })
    if(this.data.showSelect){ //显示隐藏蒙层
      this.setData({
        warpHeight: this.data.changePageHeight
      })
    }else{
      this.setData({
        warpHeight: 0
      })
    }
    if (e.target.dataset.num == 1) {  //模拟的数据，看效果用
      this.setData({
        select:that.data.sort
      })
    } else if (e.target.dataset.num == 2) {
      this.setData({
        select: that.data.floor
      })
    } else if (e.target.dataset.num == 3) {
      this.setData({
        select: [{ name: '高级' }, { name: '新春活动' }, { name: '妇女节活动' }, { name: '儿童节活动' }]
      })
    }
  },
  //点击下拉框里面的内容切换值
  selectClick(e) {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    this.setData({
      showSelect: false,
      warpHeight: 0
    })
    console.log(e);
    if (this.data.num == 1) { //点击业态切换头部的文字与选择的内容一致
      this.setData({
        type: e.target.dataset.index,
        typeId: e.target.dataset.id
      })
    } else if (this.data.num == 2) { //点击区域
      this.setData({
        address: e.target.dataset.index,
        addressId: e.target.dataset.id
      })
    } else if (this.data.num == 3) { //点击高级
      this.setData({
        more: e.target.dataset.index
      })
    }
    var sucFunc = function (that, res) {
      that.setData({
        prolist: res.data.merchant,
        sort: res.data.sort,
        floor: res.data.floor
      })
      wx.hideLoading();
    }
    var data = { address: that.data.addressId, type: that.data.typeId}
    utils.wxRequest(that, app.d.path, "Guide/index", data, sucFunc);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    that.setData({
      imgPath: app.d.imgPath
    })
    wx.request({
      url: app.d.path + 'Guide/index', //仅为示例，并非真实的接口地址
      data: {

      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        that.setData({
          prolist: res.data.merchant,
          sort: res.data.sort,
          floor: res.data.floor
          //"product": res.data.product,
          //"bannerUrls": res.data.banner,
        })
        wx.hideLoading();
      },
      fail: function () {
        console.log(1);
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        // console.log(res.windowWidth);
        console.log(res.windowHeight);
        that.setData({
          changePageHeight: res.windowHeight + 'px',
          warpHeight: 0
        })
        
      },
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})